package cn.com.zpark.servlet_config;

import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @PackageName: cn.com.zpark.servlet_config
 * @ClassName: ServletConfigDemo02
 * @Description:
 * @author: RZS
 * @date: 2021/11/10  17:30
 */
public class ServletConfigDemo02 extends HttpServlet {
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        /**
         * 任务：
         *      获取初始化参数
         *      获取servlet相关顶点配置信息
         */
        // 1、获取servletConfig对象
        ServletConfig config = getServletConfig();
        // 2、获取初始化参数
        String name = config.getInitParameter("DC");
        String value = config.getInitParameter("age");
        System.out.println(name+"："+value);

        // 获取servletContext对象
        System.out.println(config.getServletContext());
        System.out.println(config.getServletName());

    }
}
